<script src="../../../../public/admin/js/shopgoods.js"></script>{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<link rel="stylesheet" href="__STATIC__/webuploader/webuploader.css">
<script type="text/javascript" src='__STATIC__/webuploader/webuploader.js'></script>
<link rel="stylesheet" href="__PUBLIC__/admin/css/goods.css">

<section class="panel">
    {if isset($info) && !empty($info)}
    <header class="panel-heading">
        <h4>编辑</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" method="post" onsubmit="return false" role="form">
            <input type="hidden" value="{$info.id}" id="goodsid">
            <div class="form-group">
                <label class="col-sm-2 control-label">商品标题</label>
                <div class="col-sm-5">
                    <input type="text" name="title" value="{$info.title}" class="form-control" placeholder="商品标题">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">分类</label>
                <div class="col-sm-5">
                    <select name="cateid" class="form-control"  id="cateid">
                        {foreach $cate as $k =>$v}
                        <option value="{$v.category_id}" {if $v.category_id == $info.cateid}selected{/if}>{$v.category_title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">首页分类</label>
                <div class="col-sm-5">
                    <select name="homecate" class="form-control">
                        <option value="0"></option>
                        {foreach $homecate as $k =>$v}
                        <option value="{$v.id}" {if $v.id == $info.homecate}selected{/if}>{$v.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">价格</label>
                <div class="col-sm-5">
                    <input type="text" name="price" value="{$info.price}" class="form-control" placeholder="价格">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">库存</label>
                <div class="col-sm-5">
                    <input type="text" name="total" value="{$info.total}" class="form-control" placeholder="库存">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼团人数</label>
                <div class="col-sm-5">
                    <input type="text" name="groupnumber" value="{$info.groupnumber}" class="form-control" placeholder="拼团人数">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">原价</label>
                <div class="col-sm-5">
                    <input type="text" name="old_prices" value="{$info.old_prices}" class="form-control" placeholder="原价">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼团价格</label>
                <div class="col-sm-5">
                    <input type="text" name="team_prices" value="{$info.team_prices}" class="form-control" placeholder="拼团价格">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">赠送积分</label>
                <div class="col-sm-5">
                    <input type="text" name="credit" value="{$info.credit}" class="form-control" placeholder="赠送积分">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">商城类型</label>
                <div class="col-sm-5">
                    {foreach $shoptype as $k =>$v}
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $k == $info.shoptype } checked {/if} name="shoptype" value="{$k}" onchange="getValue({$k})">
                        <i class="radio "></i> {$v}
                    </label>
                    {/foreach}
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">展示图片(尺寸750*750)</label>
                <div class="col-sm-5">
                    <div id="fileList" class="uploader-list" style="float:right">
                        {foreach $info.imgs as $g}
                        <div class="file-item thumbnail draggable-element " style="position:relative;">
                            <img src="__PUBLIC__{$g}">
                            <a class="file-panel" href="javascript:;" onclick="remove(this)">
                                <span class="fa fa-close"></span>
                            </a>
                            <input type="hidden" id="data_photo" name="path[]" value="{$g}">

                        </div>
                        {/foreach}
                    </div>
                    <div id="imgPicker" style="float:left">添加图片</div>
                </div>
            </div>
            <div class="form-group ppio">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5"><span class="btn btn-default btnAddPP">添加商品型号</span></div>
            </div>
            <div class="form-group tabpp">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5" style="width: 80%">
                    <ul class="pplist"></ul>
                    <div class="ppfoot">
                        <span class="btn btn-default btnPP">添加型号分类</span>
                    </div>
                </div>
            </div>
            <div class="form-group tabpps">
                <label class="col-sm-2 control-label">价格与库存</label>
                <div class="col-sm-5" style="width: 80%">
                    <table border="1">
                        <thead>
                        <tr>
                            <td>型号</td>
                            <td>价格</td>
                            <td>拼团价格</td>
                            <td>库存</td>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td><b>批量修改</b></td>
                            <td><input type="text"></td>
                            <td><input type="text"></td>
                            <td><input type="text"></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">内容图片尺寸宽为750，长度不限</label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">内容</label>

                <div class="col-sm-10" style="width: 480px;min-height: 600px" id="editor">
                    {:htmlspecialchars_decode($info.content)}
                </div>
            </div>
            <textarea style="display: none;" id="content" name="content" >{$info.content}</textarea>

            <div class="form-group">
                <label class="col-sm-2 control-label">是否上架</label>

                <div class="col-sm-5">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $info.status == 1} checked{/if} name="status" value="1">
                        <i class="radio "></i> 上架
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio" name="status" {if $info.status == 0} checked{/if} value="0">
                        <i class="radio "></i> 不上架
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-5">
                    <input type="text" name="sort" value="{$info.sort}" class="form-control" placeholder="拼团人数">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" onclick="main.ajaxPosts(this)" data-url="{:url('admin/shopgoods/editsavegoods',array('id'=>$info.id))}"
                            class="btn btn-primary">提交
                    </button>
                </div>
            </div>
        </form>
    </div>
    {else /}
    <header class="panel-heading">
        <h4>添加商品</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" method="post" onsubmit="return false" role="form">

            <input type="hidden" value="0" id="goodsid">
            <div class="form-group">
                <label class="col-sm-2 control-label">商品标题</label>
                <div class="col-sm-5">
                    <input type="text" name="title" class="form-control" placeholder="商品标题">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">分类</label>
                <div class="col-sm-5">
                    <select name="cateid" class="form-control"  id="cateid">
                        {foreach $cate as $k =>$v}
                        <option value="{$v.category_id}">{$v.category_title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">首页分类</label>
                <div class="col-sm-5">
                    <select name="homecate" class="form-control">
                        <option value="0"></option>
                        {foreach $homecate as $k =>$v}
                        <option value="{$v.id}">{$v.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">价格</label>
                <div class="col-sm-5">
                    <input type="text" name="price" class="form-control" placeholder="价格">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">库存</label>
                <div class="col-sm-5">
                    <input type="text" name="total" class="form-control" placeholder="库存">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼团人数</label>
                <div class="col-sm-5">
                    <input type="text" name="groupnumber" class="form-control" placeholder="拼团人数">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">原价</label>
                <div class="col-sm-5">
                    <input type="text" name="old_prices" value="" class="form-control" placeholder="原价">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼团价格</label>
                <div class="col-sm-5">
                    <input type="text" name="team_prices" value="" class="form-control" placeholder="拼团价格">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">赠送积分</label>
                <div class="col-sm-5">
                    <input type="text" name="credit" value="" class="form-control" placeholder="赠送积分">
                </div>
            </div>




            <div class="form-group">
                <label class="col-sm-2 control-label">商城类型</label>

                <div class="col-sm-5">
                    {foreach $shoptype as $k =>$v}
                        <label class="radio radio-custom pull-left">
                            <input type="radio" {if $k == 1 } checked {/if} name="shoptype" value="{$k}" onchange="getValue({$k})">
                            <i class="radio "></i> {$v}
                        </label>
                    {/foreach}
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-2 control-label">快递</label>
                <div class="col-sm-5">
                    <input type="text" name="expressage" value="" class="form-control" placeholder="快递">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">地域</label>
                <div class="col-sm-5">
                    <input type="text" name="address" value="" class="form-control" placeholder="地域">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">单位</label>
                <div class="col-sm-5">
                    <input type="text" name="unit" class="form-control" placeholder="单位，如：件">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-2 control-label">展示图片(尺寸750*750)</label>
                <div class="col-sm-5">
                    <div id="fileList" class="uploader-list" style="float:right">

                    </div>
                    <div id="imgPicker" style="float:left">添加图片</div>
                </div>
            </div>
            <div class="form-group ppio">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5"><span class="btn btn-default btnAddPP">添加商品型号</span></div>
            </div>
            <div class="form-group tabpp">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5" style="width: 80%">
                    <ul class="pplist"></ul>
                    <div class="ppfoot">
                        <span class="btn btn-default btnPP">添加型号分类</span>
                    </div>
                </div>
            </div>
            <div class="form-group tabpps">
                <label class="col-sm-2 control-label">价格与库存</label>
                <div class="col-sm-5" style="width: 80%">
                    <table border="1">
                        <thead>
                        <tr>
                            <td>型号</td>
                            <td>价格</td>
                            <td>拼团价格</td>
                            <td>库存</td>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td><b>批量修改</b></td>
                            <td><input type="text"></td>
                            <td><input type="text"></td>
                            <td><input type="text"></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">内容</label>

                <div class="col-sm-10" style="width: 480px;min-height: 600px" id="editor">

                </div>
            </div>
            <textarea style="display: none;" id="content" name="content"></textarea>

            <div class="form-group">
                <label class="col-sm-2 control-label">是否上架</label>

                <div class="col-sm-5">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" checked name="status" value="1">
                        <i class="radio "></i> 上架
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio" name="status" value="0">
                        <i class="radio "></i> 不上架
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-5">
                    <input type="text" name="sort" value="" class="form-control" placeholder="排序">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" onclick="main.ajaxPosts(this)" data-url="{:url('admin/shopgoods/savegoods')}"
                            class="btn btn-primary">提交
                    </button>
                </div>
            </div>
        </form>
    </div>
    {/if}
</section>
<script>
                
    function getValue(k) {
        
        $.get('/admin/shopgoods/getcate',{shoptype:k},function (rs) {
            console.log(rs)
            $("#cateid").empty();
            var opt = '';
            var data = rs.info
            $.each(data,function(i,o){
                opt += '<option value="'+o.category_id+'">'+o.category_title+'</option>';
            });
            $("#cateid").append(opt);
        },'json');
        
    }
</script>
<script src="__PUBLIC__/admin/js/shopgoods.js"></script>

<script>

    function unescape(str) {
        var elem = document.createElement('div')
        elem.innerHTML = str
        return elem.innerText || elem.textContent
    }


    {notempty name="info"}

        {notempty name="spec_title"}


            $('.tabpp').show();
            // addPP()
            {foreach $spec_title as $v }
                var htmlppk = '';
                var boxlist = '';
                var ppvsel = '';

                var spec_list = JSON.parse(unescape("{$spec_list}"));

                $.each(spec_list,function(i,o){

                    htmlppk += '<li id="'+o.id+'" data-id="'+o.id+'"><span>'+o.title+'</span><i class="btncls2">x</i></li>';
                    if(boxlist){
                        boxlist += '<li id="1"><label><input class="ppvio" type="checkbox" value="1">sasdsa</label><i class="btncls">x</i></li>';
                    }
                });
                {foreach $v.pid_spec as $p}
                    var pppid = {$p.id};

                    var isset = "{$p.isset}";
                    var title = "{$p.title}";
                    if( isset== 1){
                        ppvsel += '<a class="ppvsel"><span data-id="'+pppid+'">'+title+'</span></a>'
                        boxlist += '<li id="'+pppid+'"><label><input class="ppvio" type="checkbox" checked value="'+pppid+'">'+title+'</label><i class="btncls">x</i></li>';
                    }else{
                        
                        boxlist += '<li id="'+pppid+'"><label><input class="ppvio" type="checkbox" value="'+pppid+'">'+title+'</label><i class="btncls">x</i></li>';
                    }
                    // <li id="'+rs.data.id+'"><label><input type="checkbox" checked="checked" value="'+rs.data.id+'">'+val+'</label></li>');

                {/foreach}
                var txtn = "{$v.title}";

                var html = '<li>' +
                    '    <div class="head">' +
                    '        <div class="sel">' +
                    '            <div class="selon" id="'+{$v.id}+'">'+txtn+'</div>' +
                    '            <ul>' + htmlppk +
                    '                <li class="btnZdy">自定义</li>' +
                    '            </ul>' +
                    '        </div>' +
                    '        <i class="btncls">x</i>' +
                    '    </div>' +
                    '    <div class="body">' +
                    '        <div class="ppvadd">' +
                    '            <div class="ppvval">'+ppvsel+'<a class="addPPV">+添加型号</a></div>' +
                    '            <div class="ppvwin">' +
                    '                <ul>' +boxlist+
                    '                </ul>' +
                    '                <div class="ppwio">' +
                    '                    <div class="ppwios">' +
                    '                        <input type="text">' +
                    '                        <a class="btn btn-default btnPPVAdd">添加</a>' +
                    '                        <a class="btn btn-default btnPPVCls">取消</a>' +
                    '                    </div>' +
                    '                    <a class="btn btn-default btnAddPPV">添加型号</a>' +
                    '                </div>' +
                    '                <div class="btns">' +
                    '                    <span class="btn btn-default btnPPVWNo">取消</span>' +
                    '                    <span class="btn btn-danger btnPPVWOk">确定</span>' +
                    '                </div>' +
                    '            </div>' +
                    '        </div>' +
                    '    </div>' +
                    '    <div class="winPPK">' +
                    '        <div class="ppktit">自定义型号分类<i class="btncls">x</i></div>' +
                    '        <div class="ppkcont">' +
                    '            请输入型号分类名称：' +
                    '            <input type="text">' +
                    '        </div>' +
                    '        <div class="ppkbtns">' +
                    '            <a class="btn btn-default">取消</a>' +
                    '            <a class="btn btn-danger">确定</a>' +
                    '        </div>' +
                    '    </div>' +
                    '</li>';
                $('.tabpp .pplist').append(html);
                // <li id="1"><label><input class="ppvio" type="checkbox" value="1">sasdsa</label><i class="btncls">x</i></li>
                // var htmlppv = '';
                // $.each(rs.data, function(i,o){
                //     htmlppv += '<li id="'+o.id+'"><label><input class="ppvio" type="checkbox" value="'+o.id+'">'+o.title+'</label><i class="btncls">x</i></li>';
                // });
                // parent.find('.ppvval').html('<a class="addPPV">+添加型号</a>');
                // parent.find('.ppvwin ul').html(htmlppv);
            {/foreach}

        {/notempty}


        {notempty name="info.spec"}

            var data = [];
            var table = [];
            var specid = [];
            var table3 = [];
            var vs = [];
            // var spec = "{$info.spec}";
            var spec = JSON.parse(unescape("{$info.spec}"));
            $.each(spec,function(i,o){
                table.push(o.title);
                specid.push(o.key);
            });
            getPPs(table,spec,specid);
        {/notempty}
    {/notempty}

</script>

<!-- <script type="text/javascript" src='https://unpkg.com/wangeditor/release/wangEditor.min.js'></script> -->
<script type="text/javascript" src='__PUBLIC__/admin/js/wangEditor.min.js'></script>

<script src="__PUBLIC__/admin/vendor/fuelux/radio.js"></script>
<script>
    var E = window.wangEditor;
    var editor = new E('#editor');
    var $content = $('#content');
    editor.customConfig.uploadFileName = 'image'
    editor.customConfig.uploadImgServer = "{:url('upload/uploadEditor')}";
    editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $content.val(html)
    };
    editor.customConfig.menus = [
        'head',  // 标题
        'bold',  // 粗体
        'fontSize',  // 字号
        'fontName',  // 字体
        'foreColor',  // 文字颜色
        'backColor',  // 背景颜色
        'link',  // 插入链接
        'list',  // 列表
        'justify',  // 对齐方式
        'quote',  // 引用
        'image',  // 插入图片
    ]
    editor.create()

    $(function(){
        $(".w-e-text-container").css('height','600px')
    })
</script>
<script >
    var $list = $('#fileList');
    var uploader = WebUploader.create({
        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/webuploader/Uploader.swf',// swf文件路径 换成你的接收路径
        server: "{:url('admin/upload/uploadImg')}",// 文件接收服务端 换成你的接收路径
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            var up_src = data._raw.replace("\\", "\/");
            var ph_src = JSON.parse(up_src);
            console.log(ph_src);
            ph_src = ph_src.data[0].replace("\/\/", "\/");
            ph_src = ph_src.replace("\\", "\/");

            //上传成功后显示图片
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail draggable-element d-"'+file.id.substr(file.id.length-1,1)+' style="position:relative;">' +
                '<img>' +
                '<a class="file-panel" href="javascript:;" onclick="remove(this)">' +
                '<span class="fa fa-close"></span>' +
                '</a>' +
                '<input type="hidden" id="data_photo" name="path[]" value="'+ph_src+'">' +
                '</div>'
                ),
                $img = $li.find('img');

            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图 如果为非图片文件，可以不用调用此方法 100（宽） x 100（高）
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, 100, 100 );
        }
    });


    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {

    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    /**
     * [remove 移除图片]
     * @post  [file]  [文件名 （必填）]
     * @post  [obj]  [操作对象] [前台操作数据 移除dom标志]
     *
     * @return
     * @Author[summer 1012684399@qq.com] THINK MORE DO LESS
     */
    function remove(obj){
        // console.log(12);

        $(obj).parent('div').remove();

        // var html = '<input type="hidden" id="data_photo" name="path[]" value="">';
        // $('#fileList').append(html);
    }
    //确认修改onclick="main.ajaxPosts(this)"
    $('.btn-primary').click(function(e) {
        e.preventDefault();
        // location.href="{:url('meallist')}";
    })


</script>
{/block}
{block name="footer"}
<script src="__PUBLIC__/admin/vendor/fuelux/checkbox.js">
    $('input[name=checkbox]').click(function(){
        $(this).attr('checked','checked').siblings().removeAttr('checked');
    });

</script>

{/block}